package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.Licence
import de.baumann.browser.iview.ILicenceManagerView
import de.baumann.browser.model.LicenceModel

class LicenceManagerPresenter : CanCreatePoolPresenter<ILicenceManagerView>() {
    private val licenceModel = LicenceModel()

    /**
     * 获取未激活的licence
     */
    fun getInActivatedLicences() {
        this.licenceModel.inactivatedLicences
                .subscribe(object : OdinObserver<List<Licence>>(view) {
                    override fun onSuccess(data: List<Licence>?) {
                        if (view != null && data != null) {
                            view.setLicences(data)
                        }
                    }
                })
    }

    /**
     * 转赠
     */
    fun licenceGift(receiveAccount: String) {
        this.licenceModel.licenceGift(view.getLicenceId(), receiveAccount)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        if (view != null)
                            view.giftSuccess()
                    }
                })
    }
}